package cn.pzhu.java.ch06;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DB01 {

	public static void main(String[] args) throws SQLException,
			ClassNotFoundException {
		String url = "jdbc:mysql://localhost:3306/javadb?useUnicode=true&characterEncoding=UTF-8";
		String user = "root";
		String password = "123456";
		// 0.load MySQL driver
		Class.forName("com.mysql.jdbc.Driver");
		// 1.create Connection
			Connection conn = DriverManager.getConnection(url, user, password);
		//2 Statemenet
			Statement st=conn.createStatement();
		//3 resetset
			ResultSet rs=st.executeQuery("SELECT ID,NAME,AGE FROM Users");
			
			//data handle
			while(rs.next()){
				long id=rs.getLong("ID");
				String name=rs.getString("NAME");
				int age=rs.getInt("AGE");
				System.out.println("ID:"+id+" NAME:"+name+" AGE:"+age);
				
			}
		//4.release reousce
			rs.close();
			st.close();
			conn.close();
	}

}
